package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduVideo;
import com.atguigu.eduservice.openfeign.VodClient;
import com.atguigu.eduservice.service.EduVideoService;
import com.atguigu.servicebase.exceptionhandler.GuliException;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import io.swagger.annotations.Api;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author ZhanK
 * @since 2022-02-20
 */
@Api(description = "小节管理")
@CrossOrigin
@RestController
@RequestMapping("/eduservice/eduvideo")
public class EduVideoController {
    @Autowired
    EduVideoService eduVideoService;


    //添加小节
    @PostMapping(value = ("addEduVideo"))
    public R addEduVideo(@RequestBody EduVideo eduVideo) {

        eduVideoService.save(eduVideo);
        return R.ok();
    }

    //删除小节 、后续还要完善通过分布式远程调用接口，nacos和openfeign实现
    @DeleteMapping(value = ("{EduVideoId}" ))
    public  R deleteEduVideoById (@PathVariable String EduVideoId){

        //删除小节
        R r = eduVideoService.removeByVideoId(EduVideoId);
        return r;
    }

    //修改小节
    @PutMapping(value = ("updateEduVideo"))
    public  R updateEduVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.updateById(eduVideo);
        return R.ok();
    }
    //根据小节ID查询小节信息
    @GetMapping(value = ("{EduVideoId}"))
    public R getEduVideoById(@PathVariable String EduVideoId  ){

        EduVideo eduVideo = eduVideoService.getById(EduVideoId);

        return R.ok().data("eduVideo",eduVideo);

    }

}

